#include "Test.TexturedBatch.h"

#undef  APP_NAME
#define APP_NAME	TexturedBatchScissor
#undef  APP_BASE
#define APP_BASE	TestTexturedBatch


class APP_NAME : public APP_BASE
{
public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}
	
	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->Clear( true, true, false );

		const rect	texc( 0.0f, 0.0f, 1.0f, 1.0f );

		batch.AddBatch( material, Rect2D( rect(-0.95f, -0.45f, 0.7f, 0.95f), texc, color4u(255) ) );
		
		//batch.AddBatch( material, Rect2D( rect(-0.1f, -0.95f, 0.95f, 0.3f), texc, color4u(255) ) );
		
		//batch.AddBatch( material, Rect2D( rect(-0.4f, -0.4f, 0.4f, 0.4f), texc, color4u(255) ) );

		//batch.AddBatch( material, Rect2D( rect(-0.6f, -0.9f, 0.4f, -0.55f), texc, color4u(255) ) );

		batch.Flush();
		batch.Clear();
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		APP_BASE::OnEnter();
		
		RenderState::ColorState	cs;
		cs.blend		= true;
		cs.blendFuncSrc	= gl_blend_func::SRC_ALPHA;
		cs.blendFuncDst	= gl_blend_func::ONE_MINUS_SRC_ALPHA;

		material.SetColorState( cs );

		ESS()->GetGraphicsEngine()->GetBatchRender()->ScissorTest( true );
		ESS()->GetGraphicsEngine()->GetBatchRender()->Scissor( rect( -0.5f, -0.5f, 0.5f, 0.5f ) );
	}
};